package me.zk.practice1.s;

import java.util.Stack;

/**
 * @author zhangkai
 * @date 2023/7/14 10:53
 */
public class LS_Offer_31 {
    public boolean validateStackSequences(int[] pushed, int[] popped) {
        Stack<Integer> stack = new Stack<>();
        int i = 0;

        for (int s : pushed) {
            stack.push(s);
            while (!stack.isEmpty() && popped[i] == stack.peek()) {
                stack.pop();
                i++;
            }
        }
        return stack.isEmpty();
    }
}
